package com.cayden.componets.canal.handle;

import com.alibaba.otter.canal.protocol.FlatMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;


/**
 * @author cayden
 * @version V1.0
 * @date 2020/12/5 9:42
 */
@Slf4j
public abstract class CanalHandle {

    protected boolean hasPrintLog = false;

    final void changeMethod(CanalContext canalContext){
        String type = canalContext.getFlatMessage().getType();
        if (StringUtils.isBlank(type)){
            return;
        }

        if (type.equalsIgnoreCase("update")){
            updateHandleInfo(canalContext);
        }

        if (type.equalsIgnoreCase("insert")){
            insertHandleInfo(canalContext);
        }

        if (type.equalsIgnoreCase("delete")){
            deleteHandleInfo(canalContext);
        }

    }


    final void handleInfo(CanalContext canalContext){
        changeMethod(canalContext);
    }

    /**
     * 处理更新应该做的事情
     */
    public abstract void updateHandleInfo(CanalContext canalContext);

    /**
     * 处理插入应该做的事情
     */
    public abstract void insertHandleInfo(CanalContext canalContext);

    /**
     * 处理删除应该做的事情
     * @param canalContext
     */
    public abstract void deleteHandleInfo(CanalContext canalContext);


    public void printCanalLog(FlatMessage flatMessage){
        // 日志
    }

    //todo 对于失败的记录和未处理记录的记录

}
